import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import {createRouter, createWebHashHistory, RouteRecordRaw} from 'vue-router';

export const asyncRoutes = [
    {
        path: '/main',
        name: 'main',
        component: () => import('@/view/main/index.vue')
    },
    {
        path: '/:pathMatch(.*)',
        redirect: '/main'
    }
];

const router = createRouter({
    history: createWebHashHistory(),
    routes: [...asyncRoutes] as RouteRecordRaw[]
});

router.beforeEach(async (to, from, next) => {
    NProgress.start();
    next();
});

router.afterEach(() => {
    NProgress.done();
});

export default router;
